home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / gempp19.zoo / gem++19 / src / gemc.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-05  |  1.7 KB  |  67 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is Copyright 1993 by Warwick W. Allison.
  4. //  This file is part of the gem++ library.
  5. //  You are free to copy and modify these sources, provided you acknowledge
  6. //  the origin by retaining this notice, and adhere to the conditions
  7. //  described in the file COPYING.LIB.
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11. #include "gemc.h"
  12. #include "grect.h"
  13.  
  14. static const int UNLIMITED=-1;
  15.  
  16. GEMcanvas::GEMcanvas(GEMform& form, int RSCindex, int width, int height) :
  17.     GEMscrollableobject(form,RSCindex),
  18.     x(0),y(0),
  19.     w(width),h(height)
  20. {
  21. }
  22.  
  23. GEMcanvas::GEMcanvas(GEMform& form, int RSCindex) :
  24.     GEMscrollableobject(form,RSCindex),
  25.     x(0),y(0),
  26.     w(UNLIMITED),h(UNLIMITED)
  27. {
  28. }
  29.  
  30. void GEMcanvas::Scroll(int pixels_right, int pixels_down)
  31. {
  32.     if (w!=UNLIMITED) {
  33.         if (x+GEMuserobject::Width()+pixels_right > CanvasWidth()) {
  34.             pixels_right = CanvasWidth()-x-GEMuserobject::Width();
  35.         } else if (x+pixels_right < 0) {
  36.             pixels_right=-x;
  37.         }
  38.     }
  39.  
  40.     if (h!=UNLIMITED) {
  41.         if (y+GEMuserobject::Height()+pixels_down > CanvasHeight()) {
  42.             pixels_down = CanvasHeight()-y-GEMuserobject::Height();
  43.         } else if (y+pixels_down < 0) {
  44.             pixels_down=-y;
  45.         }
  46.     }
  47.  
  48.     x+=pixels_right;
  49.     y+=pixels_down;
  50.  
  51.     GEMscrollableobject::Scroll(pixels_right,pixels_down);
  52. }
  53.  
  54. void GEMcanvas::ScrollTo(int nx, int ny)
  55. {
  56.     Scroll(nx-x,ny-y);
  57. }
  58.  
  59. void GEMcanvas::RedrawClipped(int ox, int oy, const GRect& oarea)
  60. {
  61.     r_recfl(oarea.g_x,oarea.g_y,oarea.g_x+oarea.g_w-1,oarea.g_y+oarea.g_h-1);
  62.     clip(oarea.g_x,oarea.g_y,oarea.g_x+oarea.g_w-1,oarea.g_y+oarea.g_h-1);
  63.     GRect area(oarea.g_x-x,oarea.g_y-y,oarea.g_w,oarea.g_h);
  64.     DrawAt(ox-x,oy-y,area);
  65.     clip_off();
  66. }
  67.